home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / Crypt-Oh / Patches.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  3.5 KB  |  131 lines

  1. // Source Code generated by PatchMaker 1.1
  2. // a sick idea by Paul Baxter
  3. //
  4. // paul@paulbaxter.com
  5. // ProcInfo for additional traps by Matthew Dolan
  6.  
  7. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  8.     #error Sorry Can't do that
  9. #endif
  10.  
  11. #include <MixedMode.h>
  12. #include <Appearance.h>
  13. #include <SpeechSynthesis.h>
  14. #include <A4Stuff.h>
  15.  
  16. // enums for routinedescriptor
  17. enum {
  18.     uppDrawStringProcInfo = kPascalStackBased
  19.         |    STACK_ROUTINE_PARAMETER(1,kFourByteCode),
  20.     uppPatchExtraInfo    // not used
  21. };
  22.  
  23. // Function Prototypes
  24. extern pascal void myDrawStringPatch(long param1);
  25.  
  26.  
  27. // Globals to hold original routine descriptors
  28. RoutineDescriptorPtr gOriginalDrawString = nil;
  29.  
  30.  
  31. // Tell MetroWerks the procInfo for main
  32. ProcInfoType __procinfo =  kPascalStackBased;
  33. pascal void main(void)
  34. {
  35.     RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
  36.     UInt32 size;
  37.     UInt16 index;
  38.     THz theZone;
  39.  
  40.     // get globals
  41.     EnterCodeResource();
  42.     // detach ourselves
  43.     DetachResource(Get1Resource('INIT', 0));
  44.  
  45.     // make sure we are in the system heap
  46.     theZone = GetZone();
  47.     SetZone(SystemZone());
  48.     
  49.     unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
  50.  
  51.     originaldesc = NGetTrapAddress(_DrawString, (_DrawString & 0x0800) ? ToolTrap : OSTrap);
  52.     if (originaldesc != unImplimentedTrapAddr) {
  53.         if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
  54.             // Trap is 68K
  55.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
  56.             // allocate new descriptor
  57.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  58.             if (!newdesc) {
  59.                 Debugger();
  60.                 return;
  61.             }
  62.             // set fields of routine decscriptor
  63.             newdesc->goMixedModeTrap = _MixedModeMagic;
  64.             newdesc->version = 7;
  65.             newdesc->routineDescriptorFlags = 0;
  66.             newdesc->reserved1 = 0;
  67.             newdesc->reserved2 = 0;
  68.             newdesc->selectorInfo = 0;
  69.             newdesc->routineCount = 0;
  70.             index = 0;
  71.             gOriginalDrawString = originaldesc;
  72.             newdesc->routineRecords[index].procInfo = uppDrawStringProcInfo;
  73.             newdesc->routineRecords[index].reserved1 = 0;
  74.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  75.             newdesc->routineRecords[index].routineFlags = 4;
  76.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)myDrawStringPatch;
  77.             newdesc->routineRecords[index].reserved2 = 0;
  78.             newdesc->routineRecords[index].selector = 0;
  79.         }
  80.         else {
  81.             // Trap is PPC
  82.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
  83.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  84.             if (!newdesc) {
  85.                 DebugStr("\pFailed to allocate RoutineDescriptor");
  86.                 return;
  87.             }
  88.             BlockMoveData(originaldesc, newdesc, size);
  89.             gOriginalDrawString = originaldesc;
  90.             index = 0;
  91.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)myDrawStringPatch;
  92.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  93.         }
  94.         NSetTrapAddress((UniversalProcPtr) newdesc, _DrawString, (_DrawString & 0x0800) ? ToolTrap : OSTrap);
  95.     }
  96.  
  97.     // restore to original heap
  98.     SetZone(theZone);
  99.     // restore globals
  100.     ExitCodeResource();
  101. }
  102.  
  103. //
  104. //
  105. // Lame text replacing code by Mark Darling.
  106. //
  107. //
  108. short  Index;
  109. Str255 TheText;
  110. char   Letter;
  111.  
  112. pascal void myDrawStringPatch(long param1)
  113. {
  114.     // Get globals
  115.     EnterCodeResource();
  116.     
  117.     TheText[0] = ( char ) *( ( char *)param1 );
  118.     
  119.     for( Index = 1; Index <= TheText[0]; Index++ )
  120.     {
  121.         Letter =~ ( char ) *( ( char *)param1 + Index );
  122.         TheText[Index] = (~Letter-1/(~(Letter|32)/13*2-11)*13);
  123.     }
  124.     
  125.     CALL_ONE_PARAMETER_UPP( gOriginalDrawString, uppDrawStringProcInfo, TheText);
  126.     
  127.     // Release globals
  128.     ExitCodeResource();
  129. }
  130.  
  131.